/*
 * @lc app=leetcode.cn id=605 lang=typescript
 *
 * [605] 种花问题
 */

// @lc code=start
function canPlaceFlowers(flowerbed: number[], n: number): boolean {
    for (let i = 0; i < flowerbed.length; i++) {
        const prev = flowerbed[i - 1];
        const next = flowerbed[i + 1];
        const element = flowerbed[i];
        if (!prev && !next && !element) {
            // 将花朵种植下去
            flowerbed[i] = 1;
            n--;
        }
    }
    return n <= 0;
}
// @lc code=end
